package artid.com.arttogoa;

import java.util.ArrayList;
import java.util.List;
import artid.com.arttogoa.fragment.TransactionRecord_Fragment;
import artid.com.arttogoa.volley.VolleyBasic;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;

/**
 * 
*    
* 项目名称：ArtworkArtA   
* 类名称   ：TransactionRecord_Activity   
* 类描述   ：交易记录   
* 创建人   ：耿卫斌   
* 创建时间：2016-7-19 下午3:37:27   
*
 */
public class TransactionRecord_Activity extends BaseActivity implements OnClickListener{
	private Context mContext;
	private RadioGroup mRadioGroup;
	private RadioButton allRB,incomeRB,expenditureRB;
	private ViewPager mViewPager;
	private List<Fragment> fragementlist;
	private int whichActivity=0;//默认我的出售 （0：全部 1：收入  2：支出）
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_transactionrecord);
		setContent(this, getIntent());
		mContext=TransactionRecord_Activity.this;
		initView();
	}
	
	private void initView(){
		VolleyBasic.showLoding(mContext);
		mTittle.setText("交易记录");
		setBack();
		whichActivity=getIntent().getIntExtra("transactionRecord_whichActivity", 0);
		mRadioGroup = (RadioGroup) findViewById(R.id.transactionRecord_RadioGroup);
		// 得到RadioGroup中的RadioButton按钮
		allRB=(RadioButton) findViewById(R.id.transactionRecord_allRB);
		allRB.setOnClickListener(this);
		incomeRB=(RadioButton) findViewById(R.id.transactionRecord_incomeRB);
		incomeRB.setOnClickListener(this);
		expenditureRB=(RadioButton) findViewById(R.id.transactionRecord_expenditureRB);
		expenditureRB.setOnClickListener(this);
		mViewPager = (ViewPager) findViewById(R.id.transactionRecord_pager);
		fragementlist = new ArrayList<Fragment>();
		TransactionRecord_Fragment all_Fragment = new TransactionRecord_Fragment(0);
		TransactionRecord_Fragment income_Fragment = new TransactionRecord_Fragment(1);
		TransactionRecord_Fragment expenditure_Fragment = new TransactionRecord_Fragment(2);
		fragementlist.add(all_Fragment);
		fragementlist.add(income_Fragment);
		fragementlist.add(expenditure_Fragment);
		mViewPager.setAdapter(new MyPageadapter(getSupportFragmentManager()));
		// 实现滑动 绑定监听（滑动页面并改变RadioButton的改变）
		mViewPager.setOnPageChangeListener(onPage);
		mViewPager.setCurrentItem(whichActivity);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.transactionRecord_allRB:
			//全部
			mViewPager.setCurrentItem(0);
			break;
		case R.id.transactionRecord_incomeRB:
			//收入
			mViewPager.setCurrentItem(1);
			break;
		case R.id.transactionRecord_expenditureRB:
			//支出
			mViewPager.setCurrentItem(2);
			break;

		default:
			break;
		}
	}
	
	// 实现滑动
		class MyPageadapter extends FragmentPagerAdapter {

			public MyPageadapter(FragmentManager fm) {
				super(fm);
				// TODO Auto-generated constructor stub
			}

			@Override
			public Fragment getItem(int arg0) {
				// TODO Auto-generated method stub
				return fragementlist.get(arg0);
			}

			@Override
			public int getCount() {
				// TODO Auto-generated method stub
				return fragementlist.size();
			}
		}

		OnPageChangeListener onPage=new OnPageChangeListener(){

			// 滑动页面并改变RadioButton的改变
			@Override
			public void onPageSelected(int position) {
				// TODO Auto-generated method stub
				if(position==0){
					allRB.setChecked(true);
				}else if(position==1){
					incomeRB.setChecked(true);
				}else if(position==2){
					expenditureRB.setChecked(true);
				}
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub

			}

		};
}
